package com.qf.mapper;

import com.qf.entity.SysPermission;
import com.qf.entity.SysRole;
import com.qf.entity.SysUser;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>title: com.qf.mapper</p>
 * <p>Company: wendao</p>
 * author zhuximing
 * date 2021/9/23
 * description:
 */
public interface UserMapper {

    @Select("select * from sys_user where user_name=#{userName}")
    public SysUser findUserByName(String userName);


    //获取用户的角色列表
    @Select("select sys_role.*\n" +
        "from sys_user_role sr left join sys_role on sys_role.role_code = sr.role_id\n" +
        "where  sr.user_id = #{userId}")
    public List<SysRole> findRolesByUserId(String  userId);

    @Select("SELECT sp.* from sys_user_role sur\n" +
        "LEFT JOIN sys_role_permission srp on sur.role_id = srp.role_id\n" +
        "LEFT JOIN sys_permission sp on sp.perm_code = srp.perm_id\n" +
        "where sur.user_id = #{userId}")
    public List<SysPermission> findPermissionByUserId(String userId);

}
